package leetcode算法面试题.字符串;

public class 验证回文串 {
        //双指针解决
        class Solution{
            public boolean isPalindrome(String s) {
                if (s.length()==0) return false;
                int left = 0;
                int right = s.length()-1;
                while (left<right) {
                    //只考虑字母和数字 所以不是字母或者数字就直接过滤
                    while (left < right && !Character.isLetterOrDigit(s.charAt(left))) left++;
                    while (left < right && !Character.isLetterOrDigit(s.charAt(right))) right--;
                    //然后把两个字母转为小写然后进行判断
                    if (Character.toLowerCase(s.charAt(left))!=Character.toLowerCase(s.charAt(right))){
                        return false;
                    }
                    left++;
                    right--;
                }
                return true;
            }
        }

}
